﻿using System;
using Ninject.Activation;
using Ninject.Modules;

namespace InstantWatch {
	public class NetflixModule : NinjectModule {
		public override void Load() {
			Bind<IProxy>().To<AggregateProxy>().InSingletonScope();
			//Bind<IProxy>().To<LocalDataProxy>().InSingletonScope();
			Bind<RssSettings>().ToProvider(new RssSettingsProvider()).InSingletonScope();
			Bind<AuthTokens>().ToProvider(new AuthTokensProvider()).InSingletonScope();
		}
	}

	public class RssSettingsProvider : Provider<RssSettings> {
		protected override RssSettings CreateInstance(IContext context) {
			return new RssSettings()
			{
				Url = @"http://www.hulu.com/feed/queue/jquintus"
			};
		}
	}

	public class AuthTokensProvider : Provider<AuthTokens> {

		protected override AuthTokens CreateInstance(IContext context) {
			AuthTokens tokens = null;
			try {
				tokens = AuthTokens.Load();
			} catch (Exception ex) {
				Console.WriteLine(ex);
			}
			if (tokens == null) {

				tokens = new AuthTokens()
				{
					ConsumerKey = "6adupmtwsjhzf64rq9bgqgfd",
					ConsumerSecret = "EtDcuCMYzc"
				};

				tokens.Save();
			}

			Console.WriteLine("Loaded user: " + tokens.UserId ?? "<none>");
			return tokens;
		}
	}

}
